using System;
using System.Collections.Generic;
using System.IO;
using Subsync.Core.Excludes;
using Subsync.Core.Sync;

namespace Subsync.Core.Excludes
{
	/// <summary>
	/// Author: Hoang Duc
	/// </summary>
    public class CLIManager : App
    {
        public CLIManager()
        {
        }

        public override Dictionary<string, List<object>> GetTokens()
        {
            Dictionary<string, List<object>> ret = new Dictionary<string, List<object>>();

            //for filtering
            ret.Add("ignore", new List<object>() { "ig", "ignore" });

            return ret;
        }

        public override List<KeyValuePair<string, initPointer>> GetInitPointers()
        {
            List<KeyValuePair<string, initPointer>> ret = new List<KeyValuePair<string, initPointer>>();

            //for filtering
            ret.Add(new KeyValuePair<string, initPointer>("ignore", new initPointer(this.Excludes)));

            return ret;
        }

        public void Excludes(Dictionary<string, List<object>> tokens)
        {
            if (tokens["ignore"].Count != 1)
            {
                Console.WriteLine("Usage: subsync.exe -ig/--ignore <file/folder_path>");
                return;
            }

            string filePath = tokens["ignore"][0].ToString();

            try
            {
                new Exclude(filePath).Execute();
            }
            catch (FolderDoesNotExist)
            {
                Console.WriteLine("The file / folder provided does not exist.");
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }
        }
    }
}
